package handle

import (
	"github.com/gin-gonic/gin"
	"img/model"
	"img/pkj"
)

func CreateUser(c *gin.Context) {
	username := c.PostForm("username")
	password := c.PostForm("password")
	if username == "" || password == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "字段不能为空",
		})
	}

	data := model.User{
		Username: username,
		Password: pkj.Str(password),
	}
	model.DB.Debug().Where("username = ?", username).First(&data)
	if data.ID > 0 {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "用户已存在",
		})
		return
	}
	model.DB.Debug().Create(&data)

	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "注册成功",
	})

}
